import { curry } from './utility';

export function resolvePath(protocol: string, location: string, path: string) {
  if (location) {
    return location + path;
  }
  const { hostname, port } = window.location;
  const url = `${protocol}://${hostname}:${port}${path}`;
  return url;
}
const curryingType = curry(resolvePath);

const protocols = ['http', 'https', 'ws', 'wss', 'ftp'];

const customPath = curryingType('');
const httpPath = curryingType('http', '');
const httpsPath = curryingType('https', '');
const wsPath = curryingType('ws', '');
const wssPath = curryingType('wss', '');
const ftpPath = curryingType('ftp', '');

export {
  customPath,
  httpPath,
  httpsPath,
  wsPath,
  wssPath,
  ftpPath,
}